<?php 
header("content-type:text/html;charset=utf8");
$city = $_POST['city'];
$redis = new redis();
$redis->connect('127.0.0.1','6379');
$result = $redis->get("$city");
// print_r($result);die;
if(empty($result))
{
		// print_r($city);
	$url = "http://api.k780.com:88/?app=weather.future&weaid=1&&appkey=10003&sign=b59bc3ef6191eb9f747dd4e83c99f2a4&format=json&weaid=$city";
	$content = file_get_contents($url);
	$data = json_decode($content,true);
	$result = $data['result'];
	// print_r($data);
	$result = json_encode($result);
	$redis->set("$city",$result);
	// print_r($data);
}
$result = json_decode($result,true);
// print_r($data);die;
// print_r($result);die;
$pdo = new PDO("mysql:host=127.0.0.1;dbname=07c;","root","root");
foreach ($result as $key => $value) {
	$days = $value['days'];
	// print_r($days);die;
	$temp_high = $value['temp_high'];
	$temp_low = $value['temp_low'];
	$citynm = $value['citynm'];
	$sql = "insert into weather values('','$citynm','$days','$temp_high','$temp_low')";
	$res = $pdo->exec($sql);
}
$result = json_encode($result);
if($res)
{
	echo $result;
}
else
{
	echo "失败";
}


 ?>